package com.ruoyi.yyq.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.yyq.domain.CarCoupon;
import com.ruoyi.yyq.service.ICarCouponService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 优惠券Controller
 * 
 * @author ruoyi
 * @date 2025-05-12
 */
@RestController
@RequestMapping("/coupon")
@CrossOrigin
public class CarCouponController extends BaseController
{
    @Autowired
    private ICarCouponService carCouponService;

    /**
     * 查询优惠券列表
     */
    @RequiresPermissions("coupon:coupon:list")
    @GetMapping("/list")
    public TableDataInfo list(CarCoupon carCoupon)
    {
        startPage();
        List<CarCoupon> list = carCouponService.selectCarCouponList(carCoupon);
        return getDataTable(list);
    }

    /**
     * 导出优惠券列表
     */
    @RequiresPermissions("coupon:coupon:export")
    @Log(title = "优惠券", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarCoupon carCoupon)
    {
        List<CarCoupon> list = carCouponService.selectCarCouponList(carCoupon);
        ExcelUtil<CarCoupon> util = new ExcelUtil<CarCoupon>(CarCoupon.class);
        util.exportExcel(response, list, "优惠券数据");
    }

    /**
     * 获取优惠券详细信息
     */
    @RequiresPermissions("coupon:coupon:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carCouponService.selectCarCouponById(id));
    }

    /**
     * 新增优惠券
     */
    @RequiresPermissions("coupon:coupon:add")
    @Log(title = "优惠券", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarCoupon carCoupon)
    {
        return toAjax(carCouponService.insertCarCoupon(carCoupon));
    }

    /**
     * 修改优惠券
     */
    @RequiresPermissions("coupon:coupon:edit")
    @Log(title = "优惠券", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarCoupon carCoupon)
    {
        return toAjax(carCouponService.updateCarCoupon(carCoupon));
    }

    /**
     * 删除优惠券
     */
    @RequiresPermissions("coupon:coupon:remove")
    @Log(title = "优惠券", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carCouponService.deleteCarCouponByIds(ids));
    }
}
